package com.ymatou.iapi.livebuyer.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.GetUserSigBean;
import com.ymatou.iapi.livebuyer.service.GetUserSigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.TestDataManager;
/**
*获取云通信用户签名
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserSig{
	private static GetUserSigBean getusersigBean;
	private static GetUserSigCall getusersigCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取云通信用户签名");
	}

	@Before
	public void caseUp() {
		getusersigBean=new GetUserSigBean();
		getusersigCall=new GetUserSigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getusersigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSig_001() {
		Logger.start(true,"获取云通信用户签名成功");
		try {
			getusersigBean.setUserId(1);
			getusersigCall.setData(getusersigBean);
			getusersigCall.callService();			
			Logger.verifyEquals("200", getusersigCall.getString("code"), "判断code是否为200");
			String usersig=getusersigCall.getJsonObject().get("data").getAsJsonObject().get("userSig").toString();
			String imAppId=getusersigCall.getJsonObject().get("data").getAsJsonObject().get("imAppId").toString();
			//disconf 配置 integration.properties   im.appId
			Logger.verifyNotNull(imAppId, "验证imAppId非空");
			Logger.verifyNotNull(usersig, "验证usersig非空");
			Logger.verifyEquals(usersig.length()>200, true, "usersig长度大于200");
			Logger.debug(usersig);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetUserSig_002() {
		Logger.start(true,"不输入userid失败");
		try {
			getusersigCall.setData(getusersigBean);
			getusersigCall.callService();			
			Logger.verifyEquals("100", getusersigCall.getString("code"), "判断code");
			Logger.verifyIsContains("错误的请求参数", getusersigCall.getString("message"), "判断message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSig_003() {
		Logger.start(true,"游客获取云通信用户签名成功");
		try {
			getusersigBean.setUserId(0);
			getusersigBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			getusersigCall.setData(getusersigBean);
			getusersigCall.callService();			
			Logger.verifyEquals("200", getusersigCall.getString("code"), "判断code是否为200");
			String usersig=getusersigCall.getJsonObject().get("data").getAsJsonObject().get("userSig").toString();
			String visitorId=getusersigCall.getJsonObject().get("data").getAsJsonObject().get("visitorId").toString();
			Logger.verifyNotNull(usersig, "验证usersig非空");
			Logger.verifyEquals(usersig.length()>200, true, "usersig长度大于200");
			Logger.debug(usersig);
			Map m = new LiveRoomWapper().selectLivevisitorById(getusersigBean.getDeviceId()).get(0);
			Logger.verifyEquals(visitorId, "-"+m.get("Id"), "验证Id");
			Logger.debug(m);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSig_004() {
		Logger.start(true,"同设备游客重复获取云通信用户签名成功");
		try {
			getusersigBean.setUserId(0);
			getusersigBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			getusersigCall.setData(getusersigBean);
			getusersigCall.callService();			
			Logger.verifyEquals("200", getusersigCall.getString("code"), "判断code是否为200");
			String visitorId=getusersigCall.getJsonObject().get("data").getAsJsonObject().get("visitorId").toString();
			getusersigCall.callService();	
			String visitorId2=getusersigCall.getJsonObject().get("data").getAsJsonObject().get("visitorId").toString();
			Logger.verifyEquals(visitorId, visitorId2, "验证Id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}